﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CTEM.Controllers.BUS;
using CTEM.Controllers.Global;
using CTEM.Models;
using DevExpress.XtraEditors;

namespace CTEM.ModuleForms.ManageEmployee
{
    public partial class ResetPassword : DevExpress.XtraEditors.XtraForm
    {
        private EmployeeBUS _employeeBUS = new EmployeeBUS();
        public ResetPassword()
        {
            InitializeComponent();
        }

        private void ResetPassword_Load(object sender, EventArgs e)
        {
            employerDTOBindingSource.DataSource = _employeeBUS.LoadAllUser();
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            var emp = lookUpEdit1.GetSelectedDataRow() as EmployerDTO;
            long empid = emp.employeeID;
            string pass = DataProvider.Encrypt(Constants.DEFAULT_PASSWORD);
            bool success = _employeeBUS.ResetPassword(empid, pass);
            if (success)
            {
                Global.CurrentUser.Password = pass;
                XtraMessageBox.Show(" Cập Nhật Thành Công\n Mật Khẩu Mới là: " + Constants.DEFAULT_PASSWORD,
                                       Constants.CONFIRM);
            }
            else
            {
                XtraMessageBox.Show(Constants.ERROR, Constants.CONFIRM);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}